#include "SoundPotInstrumentFactory.h"

void SoundPot::InstrumentFactory::registerSoundType(Sound::Type type, SoundTypeSpecificInstrumentFactory* specificFactory)
{
	specificFactories[type] = specificFactory;
}

SoundPot::InstrumentFactory::InstrumentFactory()
{
	existingInstruments = new std::list<Instrument*>();
}

SoundPot::InstrumentFactory::~InstrumentFactory()
{
	deleteAllInstruments();
	delete existingInstruments;
}

void SoundPot::InstrumentFactory::deleteInstrument(Instrument* instrument)
{
	existingInstruments->remove(instrument);
	delete instrument;
}

void SoundPot::InstrumentFactory::deleteAllInstruments()
{
	std::list<Instrument*>::iterator iterator;

	for(iterator = existingInstruments->begin(); iterator != existingInstruments->end(); iterator++)
	{
		delete (*iterator);
	}
	
	existingInstruments->clear();
}

SoundPot::Instrument* SoundPot::InstrumentFactory::createInstrument(const std::string& instrumentID)
{
	return 0; // Todo
}

SoundPot::Instrument* SoundPot::InstrumentFactory::createNewInstrument(Sound::Type soundType)
{
	return specificFactories[soundType]->createNewInstrument(soundType);
}